package ntd.util.frame.javacv.ai_fuming;

import cn.hutool.log.StaticLog;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Test {
    public static void main(String[] args) {
        final int DEFAULT_PORT = 8888;
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(DEFAULT_PORT);
            while (true) {
                // 阻塞监听
                Socket socket = serverSocket.accept();
                System.out.println("Client[" + socket.getPort() + "]Online");
                // 读取消息
                BufferedReader buffReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                // 发送消息
                BufferedWriter buffWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                String msg = null;
                while ((msg = buffReader.readLine()) != null) {
                    System.out.println("Client[" + socket.getPort() + "]:" + msg);
                    // 写入服务端要发送的消息
//                    buffWriter.write("Server:" + msg + "\n");
//                    buffWriter.flush();
//                    if (msg.equals("quit")) {
//                        System.out.println("Client[" + socket.getPort() + "]:Offline");
//                        break;
//                    }
                }
            }
        } catch (IOException e) {
        }

    }
}
